home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Commands / EditFlash.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  7.8 KB  |  307 lines

  1. //=========================================================================================================
  2. //
  3. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  4. //
  5. // Feature: Contributor Flash Editing
  6. // Author:  JDH
  7. // Module:  EditFlash.js
  8. // Purpose:    Flash editing dialog.
  9. // Updates:
  10. //    7/30/02 - Started file control
  11. //
  12. //=========================================================================================================
  13.  
  14. var helpDoc = MM.HELP_objFlash;
  15.  
  16. function receiveArguments()
  17. {
  18. }
  19.  
  20. function canAcceptCommand()
  21. {
  22.     if ( dw.getDocumentDOM().getCCSharedSetting_TextOnlyInNonTemplates() )
  23.         return false;
  24.     return true;
  25. }
  26.  
  27. function commandButtons()
  28. {
  29.    /*return new Array(MM.BTN_OK,         "run()",
  30.                     MM.BTN_Cancel,     "window.close()",
  31.                     MM.BTN_Help,       "displayHelp()" );
  32.  
  33.     */
  34.  
  35.     return new Array( "PutButtonsOnBottom", "OkButton", MM.BTN_OK, "run()",
  36.                       "PutButtonOnLeft", MM.BTN_Help,    "displayHelp()",
  37.                       "CancelButton", MM.BTN_Cancel,  "window.close()");
  38.  
  39.  
  40. }
  41.  
  42. var fileWidth;
  43. var fileHeight;
  44. var origWidth;
  45. var origHeight;
  46. var aspectRatio;
  47.  
  48. function initializeUI()
  49. {
  50.     var play = "";
  51.     var loop = "";
  52.     var src = "";
  53.  
  54.     // Look for the loop and play params attached to the flash
  55.     // movie
  56.  
  57.     selectedNode = dw.getDocumentDOM().getSelectedNode();
  58.         selectedNode.outerHTML = selectedNode.outerHTML;
  59.    
  60.     if ( selectedNode.childNodes )
  61.     {
  62.         for ( var index = 0; index < selectedNode.childNodes.length; index++ )
  63.         {
  64.             var node = selectedNode.childNodes[ index ];
  65.                         if ( node.tagName == "PARAM" )
  66.             {
  67.                 var nodeName = node.getAttribute( "name" );
  68.                 nodeName = nodeName.toLowerCase();
  69.                 if ( nodeName == "loop" )
  70.                     loop = node.getAttribute( "value" );
  71.                 if ( nodeName == "play" )
  72.                     play = node.getAttribute( "value" );
  73.                 if ( nodeName == "movie" )
  74.                     src = node.getAttribute( "value" );
  75.  
  76.             }
  77.         }
  78.     }
  79.  
  80.     // Set the check boxes
  81.  
  82.     if ( !play || play.toLowerCase() != "false" )
  83.         document.theForm.play.checked = true;
  84.  
  85.     if ( !loop || loop.toLowerCase() != "false" )
  86.         document.theForm.loop.checked = true;
  87.  
  88.     // set the movie title
  89.     if ( src )
  90.     {
  91.         // before we do anything else, remove any query string
  92.         var index = src.lastIndexOf("?");
  93.         if( index != -1 )
  94.             src = src.substr( 0, index );
  95.  
  96.         var filePath = unescape( src );
  97.         index = filePath.lastIndexOf("/");
  98.         if( index != -1 )
  99.             filePath = filePath.substr( index+1, filePath.length );
  100.  
  101.         document.fileName.innerHTML = filePath;
  102.  
  103.         var movieURL = dwscripts.getAbsoluteURL(unescape(src));
  104.         if (movieURL != null)
  105.         {
  106.             var moviePath = dwscripts.localURLToFilePath(movieURL);
  107.  
  108.             if (moviePath != null)
  109.             {
  110.                 var widthHeight = dw.extractWidthAndHeightFromSWF(moviePath);
  111.                 if (widthHeight != null)
  112.                 {
  113.                     fileWidth = widthHeight[0];
  114.                     fileHeight = widthHeight[1];
  115.                 }
  116.             }
  117.         }
  118.     }
  119.  
  120.     origWidth = selectedNode.getAttribute("width");
  121.     origHeight = selectedNode.getAttribute("height");
  122.  
  123.     if (fileWidth == null || fileHeight == null)
  124.         document.theForm.resetsize.disabled=true;
  125.     else
  126.     {
  127.         document.theForm.resetsize.disabled=false;
  128.         if (origWidth == null)
  129.             origWidth = fileWidth;
  130.         if (origHeight == null)
  131.             origHeight = fileHeight;
  132.     }
  133.  
  134.     if (origWidth == null || origHeight == null)
  135.     {
  136.         document.theForm.width.disabled="true";
  137.         document.theForm.widthselector.disabled="true";
  138.         document.theForm.height.disabled="true";
  139.         document.theForm.heightselector.disabled="true";
  140.         document.theForm.constraint.disabled="true";
  141.         document.theForm.resetsize.disabled="true";
  142.     }
  143.     else
  144.     {
  145.         document.theForm.width.value = origWidth;
  146.         document.theForm.height.value = origHeight;
  147.     }
  148.             
  149.     aspectRatio = fileWidth / fileHeight;
  150. }
  151.  
  152. function widthInPixels()
  153. {
  154.     var width = document.theForm.width.value;
  155.     if (document.theForm.widthselector.selectedIndex == 1)
  156.         width = Math.round((width / 100) * fileWidth);
  157.     return width
  158. }
  159.  
  160. function setWidthInPixels(width)
  161. {
  162.         if (document.theForm.widthselector.selectedIndex == 1)
  163.             document.theForm.width.value = Math.round(100 * width / fileWidth);
  164.         else
  165.             document.theForm.width.value = width;
  166. }
  167.  
  168. function heightInPixels()
  169. {
  170.     var height = document.theForm.height.value;
  171.     if (document.theForm.heightselector.selectedIndex == 1)
  172.         height = Math.round((height / 100) * fileHeight);
  173.     return height
  174. }
  175.  
  176. function setHeightInPixels(height)
  177. {
  178.         if (document.theForm.heightselector.selectedIndex == 1)
  179.             document.theForm.height.value = Math.round(100 * height / fileHeight);
  180.         else
  181.             document.theForm.height.value = height;
  182. }
  183.  
  184. function widthSet()
  185. {
  186.     if (document.theForm.constraint.checked)
  187.     {
  188.         var width = widthInPixels();
  189.         var height = Math.round(width / aspectRatio);
  190.  
  191.         setHeightInPixels(height);
  192.     }
  193. }
  194.  
  195. function heightSet()
  196. {
  197.     if (document.theForm.constraint.checked)
  198.     {
  199.         var height = heightInPixels();
  200.         var width = Math.round(height * aspectRatio);
  201.  
  202.         setWidthInPixels(width);
  203.     }
  204. }
  205.  
  206. function widthSelectorChange()
  207. {
  208.     if (document.theForm.widthselector.selectedIndex == 1)
  209.         document.theForm.width.value =
  210.             Math.round(100 * document.theForm.width.value / fileWidth);
  211.     else
  212.         document.theForm.width.value =
  213.             Math.round(fileWidth * document.theForm.width.value / 100);
  214. }
  215.  
  216. function heightSelectorChange()
  217. {
  218.     if (document.theForm.heightselector.selectedIndex == 1)
  219.         document.theForm.height.value =
  220.             Math.round(100 * document.theForm.height.value / fileHeight);
  221.     else
  222.         document.theForm.height.value =
  223.             Math.round(fileHeight * document.theForm.height.value / 100);
  224. }
  225.  
  226. function resetSize()
  227. {
  228.     setWidthInPixels(fileWidth);
  229.     setHeightInPixels(fileHeight);
  230. }
  231.  
  232.  
  233. function run()
  234. {
  235.     // Set that we have not found the param tags
  236.  
  237.         var playObj = null;
  238.         var loopObj = null;
  239.         var embedObj = null;
  240.         var src;
  241.  
  242.     // Look for the param tags as well as the embed tags,
  243.     // when you find them, alter them to the new values
  244.  
  245.     selectedNode = dw.getDocumentDOM().getSelectedNode();
  246.         selectedNode.outerHTML = selectedNode.outerHTML;
  247.    
  248.     if ( selectedNode.childNodes )
  249.     {
  250.                 for ( var index = 0; index < selectedNode.childNodes.length; index++ )
  251.         {
  252.             var node = selectedNode.childNodes[ index ];
  253.                         if ( node.tagName == "PARAM" )
  254.             {
  255.                 var nodeName = node.getAttribute( "name" );
  256.                 nodeName = nodeName.toLowerCase();
  257.                 if ( nodeName == "loop" )
  258.                                         loopObj = node;
  259.                 if ( nodeName == "play" )
  260.                                         playObj = node;
  261.                 if ( nodeName == "movie" )
  262.                     src = node.getAttribute( "value" );
  263.             }
  264.                         if ( node.tagName == "EMBED" )
  265.                                 embedObj = node;
  266.         }
  267.     }
  268.  
  269.     // Get the values of the check boxes
  270.  
  271.     var play = "false";
  272.     if ( document.theForm.play.checked )
  273.         play = "true";
  274.  
  275.     var loop = "false";
  276.     if ( document.theForm.loop.checked )
  277.         loop = "true";
  278.  
  279.     // If we haven't found the param tags then we need to add them
  280.         if ( embedObj )
  281.         {
  282.                 embedObj.setAttribute( "play", play );
  283.                 embedObj.setAttribute( "loop", loop );
  284.         }
  285.  
  286.         if ( loopObj )
  287.                 loopObj.setAttribute( "value", loop );
  288.         if ( playObj )
  289.                 playObj.setAttribute( "value", play );
  290.  
  291.         if ( loopObj == null )
  292.         selectedNode.innerHTML = "<param name=\"loop\" value=\"" + loop + "\">\n" + selectedNode.innerHTML;
  293.         if ( playObj == null )
  294.         selectedNode.innerHTML = "<param name=\"play\" value=\"" + play + "\">\n" + selectedNode.innerHTML;
  295.  
  296.     var newWidth = widthInPixels();
  297.     var newHeight = heightInPixels();
  298.  
  299.     if (newWidth != origWidth || newHeight != origHeight)
  300.     {
  301.         selectedNode.setAttribute("width", newWidth);
  302.         selectedNode.setAttribute("height", newHeight);
  303.     }
  304.  
  305.     window.close();
  306. }
  307.